<template>
  <div>
    <div>
      <span>开始任务&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </div>
    <el-form class="tl-form startTaskEditForm" ref="form" :model="model" :rules="rules" label-width="150px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="实际开始日期" prop="actualstartdate">
            <el-date-picker v-model="model.actualstartdate" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" :disabled="isFinish" :picker-options="pickerOptions"> </el-date-picker>
          </el-form-item>
        </el-col>
      <el-col :span="12">
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" style="float: right;margin-right: 10px !important">确认</el-button>
      </el-col>
            </el-row>
    </el-form>
  </div>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: {},
  data() {
    return {
      moduleTitle: '开始任务',
      urlPrefix: '/mpm/projectTaskFeedback/',
      url: {
        // 额外的url
        queryCodeList: '/mpm/projectTask/dataCodeList',
        start: '/mpm/projectTask/start'
      },
      isFinish: false,
      pickerOptions: {
        disabledDate: (time) => {
          let now = new Date()
          now.setHours(0, 0, 0, 0)
          return time.getTime() > now.getTime()
        }
      }
    }
  },
  props: {
    newValue: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    newValue: {
      handler(value, oldvalue) {
        this.taskid = value.taskid
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    queryData(id) {
      if (!this.url.load) {
        this.$tap.alert('请设置load地址!', 'warning')
        return
      }
      return getAction('/mpm/projectTask/load', { id: this.taskid }).then((res) => {
        if (res.success) {
          this.model = res.result
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    /** 保存确认 */
    doSubmitEdit() {
      if (!this.beforeSubmit()) {
        return
      }
      if (this.model.actualstartdate === null || this.model.actualstartdate === undefined) {
        this.$tap.alert('请选择实际开始时间', 'warning')
        return
      }
      var param = {
        ids: this.taskid,
        actualstartdate: this.model.actualstartdate
      }
      postAction(this.url.start, param).then((res) => {
        if (res.success) {
          this.$tap.message(res.message, 'success')
          this.$emit('refresh')
          this.visible = false
        } else {
          this.$tap.alert(res.message, 'warning')
        }
        this.saveLoading = false
      })
      // this.$refs.form.validate(valid => {
      //   if (valid) {
      //     if (this.isAdd) {
      //       this.doAdd()
      //       return true
      //     } else {
      //       this.doEdit()
      //     }
      //   } else {
      //     return false
      //   }
      // })
    },
    /** 执行新增提交 */
    doAdd() {
      this.saveLoading = true
      // 增加唯一单号
      postAction(this.url.add + '?billuid=' + this.uid, this.model)
        .then((res) => {
          if (res.success) {
            this.$tap.message('添加成功', 'success')
            this.model = res.result
            this.visible = false
            this.$emit('refresh')
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterSubmit()
          this.saveLoading = false
        })
        .catch((err) => {
          this.saveLoading = false
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.startTaskEditForm {
  margin-top: 16px;
  margin-left: -50px;
}
</style>
